package com.company;

/**
 * https://leetcode.cn/problems/strong-password-checker-ii/
 */

public class P039_StringPassword {

    public static void main(String[] args) {
        System.out.println(strongPasswordCheckerII("IloveLe3tcode!"));
        System.out.println(strongPasswordCheckerII("Me+You--IsMyDream"));
        System.out.println(strongPasswordCheckerII("1aB!"));
        System.out.println(strongPasswordCheckerII("yvTY#@IB#*!hjrQt-TLW&z)$@!%Duqt&ToskxHgnybqpndMI+wP&fcemIk#@KnkMTaUkcIbncpTL"));
    }

    public static boolean strongPasswordCheckerII(String password) {
        if (password.length() < 8) {
            return false;
        }
        return containsUpperCase(password)
                && containsLowerCase(password)
                && containsNum(password)
                && containsSpecial(password)
                && !containsSequence(password);
    }

    public static boolean containsUpperCase(String s) {
        char[] chars = s.toCharArray();
        for (char c : chars) {
            if (c >= 'A' && c <= 'Z') {
                return true;
            }
        }
        return false;
    }

    public static boolean containsLowerCase(String s) {
        char[] chars = s.toCharArray();
        for (char c : chars) {
            if (c >= 'a' && c <= 'z') {
                return true;
            }
        }
        return false;
    }

    public static boolean containsNum(String s) {
        char[] chars = s.toCharArray();
        for (char c : chars) {
            if (c >= '0' && c <= '9') {
                return true;
            }
        }
        return false;
    }

    public static boolean containsSpecial(String s) {
        char[] chars = s.toCharArray();
        String special = "!@#$%^&*()-+";
        for (char c : chars) {
            if (special.contains(String.valueOf(c))) {
                return true;
            }
        }
        return false;
    }

    public static boolean containsSequence(String s) {
        int length = s.length();
        for (int i = 1; i < length; i++) {
            if (s.charAt(i - 1) == s.charAt(i)) {
                return true;
            }
        }
        return false;
    }

}
